<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>微信付款</title>
  <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
  <meta content="yes" name="apple-mobile-web-app-capable"/>
  <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
  <meta content="telephone=no" name="format-detection"/>
  <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
  <script src="__STATIC__/plugs/layui/lay/modules/layer.js"></script>
  <script src="__STATIC__/plugs/qrcode/qrcode.js"></script>
</head>
<body>
<div class="layui-container">
 	<div id="qrcode" style="width:500px; height:500px; margin-top:15px;"></div>
</div>

</br>
</body>
</html>
<script type="text/javascript">
    var qrcode = new QRCode(document.getElementById("qrcode"), {
        width : 400,
        height : 400
    });
    //生成支付二维码
    function makeCode () {
        qrcode.makeCode("{$prepayid}");
    }
    makeCode();     //生成支付二维码

    //执行轮询 -- 查询支付结果进行跳转
    setInterval(function(){
        getMsgNum();
    },4000);
    //轮询函数 -- 进行跳转页面领取优惠券
    function getMsgNum() {
        var dir = '';
        var sign = "{$sign}";
        if(sign == 1){
            dir = '{:url("Weixinpay/order_sn_ajax")}?out_trade_no={$out_trade_no}';
        }else if(sign == 2){
            dir = '{:url("Weixinpay/recharge_sn_ajax")}?out_trade_no={$out_trade_no}';
        }else{
            dir = '{:url("Weixinpay/cash_coupon_sn_ajax")}?out_trade_no={$out_trade_no}';
        }
        $.ajax({
            url: dir,
            type: 'POST',
            dataType: 'json',
            success: function (data) {
                if (data.status == 1) {
//                    alert('支付成功');
                    if(sign == 1){
                        window.location.href = "{:url('PayComplete/get_coupon')}?out_trade_no={$out_trade_no}";
                    }else if(sign == 2){
                        window.location.href = "{:url('User/recharge')}";
                    }else if(sign == 3){
                        window.location.href = "{:url('User/my_coupon')}";
                    }
                }else if(data.status == -1){
//                    alert(data.msg);
                }
                console.log(data);
            }
        });
    }
</script>

